//
//  UIButton+Extension.swift
//  LRWeibo
//
//  Created by admin on 15/9/21.
//  Copyright © 2015年 懒人. All rights reserved.
//

import UIKit

extension UIButton{

    /// 便利构造函数
    convenience init(imageName: String,backImageName: String) {
    
        // 实例化按钮
       self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        // 自动调整大小
        sizeToFit()
    }
    
    convenience init(title: String,fontSize: CGFloat, color: UIColor, backImageName: String)
    {
        self.init()
        
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        
        sizeToFit()
    }

    convenience init(title: String,fontSize: CGFloat, color: UIColor, imageName: String)
    {
        self.init()
        
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: imageName), forState: .Normal)
        
        sizeToFit()
    }
}
